﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
namespace BISPOS
{
    public partial class CustomerInvoicesForm : DevExpress.XtraEditors.XtraForm
    {
        IEnumerable<Invoice> invoices;
        public CustomerInvoicesForm(IEnumerable<Invoice> _invoices, string textToShow)
        {
            InitializeComponent();
            invoices = _invoices;
            layoutControlGroup5.Text = "ลูกค้า: " + invoices.FirstOrDefault().Customer.CodeAndName;
            groupControl1.Text = textToShow;
            invoicesLinqServerModeSource.QueryableSource = invoices.AsQueryable();
        }

        private void invoicesListBoxControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Invoice invoice = ((Invoice)invoicesListBoxControl.SelectedItem);

                dateTextEdit.Text = invoice.Date.ToShortDateString();
                idTextEdit.Text = invoice.Id.ToString().PadLeft(8, '0');
                paymentTypeTextEdit.Text = invoice.PaymentType.Name;
                if (invoice.PaymentType.IsCredit)
                {
                    paymentTypeTextEdit.Text += ", เงินเชื่อ";
                }
                else
                {
                    paymentTypeTextEdit.Text += ", เงินสด";
                }
                totalPriceTextEdit.Text = invoice.TotalPrice.ToString("n2");
                employeeTextEdit.Text = invoice.Employee.Name;

                invoiceItemslinqServerModeSource.QueryableSource = invoice.InvoiceItems.AsQueryable();
            }
            catch { }
        }
    }
}